var $tableFirstColumn;
var $tableOfEachRow;
var $search;


$(function(){
	$projectContent = $(".project-register .project-display .content");
	$search = $(".project-register #search");
	$tableOfEachRow = $(".project-register table tr:not(:first)");
	$tableFirstColumn = $tableOfEachRow.find("td:first");

	setProjectDisplayScroll();
	
	setSearchFocusListener();
	
});
function setProjectDisplayScroll(){
	$projectContent.mCustomScrollbar({
		theme:"white",
		scrollButtons:{
			enable:false
		},
		autoHideScrollbar:true,
		scrollInertia:100,
		horizontalScroll:false,
	});
}

function setSearchFocusListener(){
	$search.focus(function(){
		$search.velocity({width:"180px"}, 200, "ease");
		addSearchListener();
	});
	$search.blur(function(){
		$search.velocity({width:"100px"}, 200, "ease")
	});
}

function addSearchListener(){
	$search.on('input', function(){
		for(var i = 0; i < $tableFirstColumn.length; i++){
			var $oneTd = $tableFirstColumn.get(i).innerHTML.toLowerCase();
			while($oneTd.indexOf(" ") != -1){
				$oneTd = $oneTd.replace(" ", "");
			}
			if($oneTd.search($search.val().toLowerCase()) != -1){
				$tableOfEachRow.get(i).style.display = "block";
			}else{
				$tableOfEachRow.get(i).style.display = "none";
			}
			var $array = $search.val().toLowerCase().split(" ");
			for(var j = 0; j < $array.length; j++){
				if($oneTd.search($array[j]) != -1){
					if($array[j] != ""){
						$tableOfEachRow.get(i).style.display = "block";	
					}
				}				
			}
		}
	});
};

